home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_5.lha / 5_5 / 5_5c3i.c < prev    next >
Text File  |  1993-08-08  |  898b  |  45 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  6. * The C++ Answer Book */
  7. * Tony Hansen */
  8. * All rights reserved. */
  9. ifdef NONLOCAL    /* DELETE */
  10. include <intset.h>
  11. else /* DELETE */
  12. include "intset.h" /* DELETE */
  13. endif /* DELETE */
  14.  
  15. / remove a member from an intset
  16. oid intset::remove(int t)
  17.  
  18.    // look for the member
  19.    // using a binary search,
  20.    // just as was done in
  21.    // intset::member()
  22.    int l = 0;
  23.    int u = cursize - 1;
  24.  
  25.    while (l <= u)
  26. {
  27. int m = (l+u) / 2;
  28.  
  29. if (t < x[m]) u = m - 1;
  30.  
  31. else if (t > x[m]) l = m + 1;
  32.  
  33. else    // found it, shift the remaining
  34.     {    // elements to the left
  35.     for (int n = m + 1; n < cursize; n++, m++)
  36.     x[m] = x[n];
  37.  
  38.     cursize--;
  39.     return;
  40.     }
  41. }
  42.  
  43.    // not found, do nothing
  44.  
  45.